using System.Collections.Generic;

namespace Toolbox.DnsService.Models
{
    /// <summary>
    /// DNS服务配置模型
    /// 作者：huobing
    /// </summary>
    public class DnsServiceConfig
    {
        /// <summary>
        /// 是否启用服务
        /// </summary>
        public bool IsEnabled { get; set; } = false;
        
        /// <summary>
        /// 监听端口
        /// </summary>
        public int Port { get; set; } = 153;
        
        /// <summary>
        /// 上游DNS服务器列表
        /// </summary>
        public List<string> UpstreamDnsServers { get; set; } = new();
        
        /// <summary>
        /// DNS缓存记录
        /// </summary>
        public Dictionary<string, string> DnsCache { get; set; } = new();
        
        /// <summary>
        /// DNS记录字典
        /// </summary>
        public Dictionary<string, string> DnsRecords { get; set; } = new();
        
        /// <summary>
        /// 是否启用日志记录
        /// </summary>
        public bool EnableLogging { get; set; } = true;
        
        /// <summary>
        /// 日志文件路径
        /// </summary>
        public string LogFilePath { get; set; } = string.Empty;
        
        /// <summary>
        /// 缓存过期时间（分钟）
        /// </summary>
        public int CacheExpirationMinutes { get; set; } = 60;
        
        /// <summary>
        /// 最大并发连接数
        /// </summary>
        public int MaxConnections { get; set; } = 100;
        
        /// <summary>
        /// 是否自动启动
        /// </summary>
        public bool AutoStart { get; set; } = false;
    }
    
    /// <summary>
    /// DNS测试结果模型
    /// 作者：huobing
    /// </summary>
    public class DnsTestResult
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }
        
        /// <summary>
        /// 响应时间（毫秒）
        /// </summary>
        public long ResponseTimeMs { get; set; }
        
        /// <summary>
        /// 解析的IP地址
        /// </summary>
        public string? ResolvedIp { get; set; }
        
        /// <summary>
        /// 错误消息
        /// </summary>
        public string? ErrorMessage { get; set; }
        
        /// <summary>
        /// 测试时间
        /// </summary>
        public DateTime TestTime { get; set; } = DateTime.Now;
    }
    
    /// <summary>
    /// UDP测试结果模型
    /// 作者：huobing
    /// </summary>
    public class UdpTestResult
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }
        
        /// <summary>
        /// 响应时间（毫秒）
        /// </summary>
        public long ResponseTimeMs { get; set; }
        
        /// <summary>
        /// 错误消息
        /// </summary>
        public string? ErrorMessage { get; set; }
        
        /// <summary>
        /// 测试时间
        /// </summary>
        public DateTime TestTime { get; set; } = DateTime.Now;
    }
    
    /// <summary>
    /// DNS记录模型
    /// 作者：huobing
    /// </summary>
    public class DnsRecord
    {
        /// <summary>
        /// 域名
        /// </summary>
        public string Domain { get; set; } = string.Empty;
        
        /// <summary>
        /// IP地址
        /// </summary>
        public string IP { get; set; } = string.Empty;
        
        /// <summary>
        /// 记录类型
        /// </summary>
        public string RecordType { get; set; } = "A";
        
        /// <summary>
        /// 生存时间（秒）
        /// </summary>
        public int Ttl { get; set; } = 3600;
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.Now;
        
        /// <summary>
        /// 最后更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.Now;
        
        /// <summary>
        /// 键（用于字典操作）
        /// </summary>
        public string Key => Domain;
        
        /// <summary>
        /// 值（用于字典操作）
        /// </summary>
        public string Value => IP;
    }
    
    /// <summary>
    /// DNS查询请求模型
    /// 作者：huobing
    /// </summary>
    public class DnsQueryRequest
    {
        /// <summary>
        /// 查询ID
        /// </summary>
        public ushort Id { get; set; }
        
        /// <summary>
        /// 查询标志
        /// </summary>
        public ushort Flags { get; set; }
        
        /// <summary>
        /// 查询数量
        /// </summary>
        public ushort QuestionCount { get; set; }
        
        /// <summary>
        /// 回答数量
        /// </summary>
        public ushort AnswerCount { get; set; }
        
        /// <summary>
        /// 权威记录数量
        /// </summary>
        public ushort AuthorityCount { get; set; }
        
        /// <summary>
        /// 附加记录数量
        /// </summary>
        public ushort AdditionalCount { get; set; }
        
        /// <summary>
        /// 查询域名
        /// </summary>
        public string Domain { get; set; } = string.Empty;
        
        /// <summary>
        /// 查询类型
        /// </summary>
        public ushort QueryType { get; set; }
        
        /// <summary>
        /// 查询类
        /// </summary>
        public ushort QueryClass { get; set; }
    }
    
    /// <summary>
    /// DNS查询响应模型
    /// 作者：huobing
    /// </summary>
    public class DnsQueryResponse
    {
        /// <summary>
        /// 查询ID
        /// </summary>
        public ushort Id { get; set; }
        
        /// <summary>
        /// 响应标志
        /// </summary>
        public ushort Flags { get; set; }
        
        /// <summary>
        /// 查询数量
        /// </summary>
        public ushort QuestionCount { get; set; }
        
        /// <summary>
        /// 回答数量
        /// </summary>
        public ushort AnswerCount { get; set; }
        
        /// <summary>
        /// 权威记录数量
        /// </summary>
        public ushort AuthorityCount { get; set; }
        
        /// <summary>
        /// 附加记录数量
        /// </summary>
        public ushort AdditionalCount { get; set; }
        
        /// <summary>
        /// 回答记录
        /// </summary>
        public List<DnsAnswerRecord> Answers { get; set; } = new();
        
        /// <summary>
        /// 响应时间（毫秒）
        /// </summary>
        public long ResponseTimeMs { get; set; }
    }
    
    /// <summary>
    /// DNS回答记录模型
    /// 作者：huobing
    /// </summary>
    public class DnsAnswerRecord
    {
        /// <summary>
        /// 域名
        /// </summary>
        public string Domain { get; set; } = string.Empty;
        
        /// <summary>
        /// 记录类型
        /// </summary>
        public ushort RecordType { get; set; }
        
        /// <summary>
        /// 记录类
        /// </summary>
        public ushort RecordClass { get; set; }
        
        /// <summary>
        /// 生存时间（秒）
        /// </summary>
        public int Ttl { get; set; }
        
        /// <summary>
        /// 数据长度
        /// </summary>
        public ushort DataLength { get; set; }
        
        /// <summary>
        /// IP地址
        /// </summary>
        public string IpAddress { get; set; } = string.Empty;
    }
}